package com.jiu345.api.controller;

import com.jiu345.api.pojo.Goods;
import com.jiu345.api.pojo.GoodsCategory;
import com.jiu345.api.pojo.GoodsSkus;
import com.jiu345.api.pojo.bo.GoodsBo;
import com.jiu345.api.service.IGoodsCateService;
import com.jiu345.api.service.IGoodsService;
import com.jiu345.core.page.PageQuery;
import com.jiu345.core.page.TableDataInfo;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * package:IndexController
 * @author MrLei QQ:235921049
 * @date 2024-05-21
 * desc:首页
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/index")
public class IndexController extends BaseController {
    private final IGoodsService goodsService;
    private final IGoodsCateService cateService;

    /*获取所有一级分类*/
    @GetMapping("/cateOne")
    public R<List<GoodsCategory>> index(){
        List<GoodsCategory> cateOne = cateService.getOne();
        return R.ok(cateOne);
    }

    /*TODO 根据SKU查询销量、新品商品前20条商品,暂不调用此方法*/
    @GetMapping("/goods/sku")
    public R<List<GoodsSkus>> selectSkuBy(GoodsSkus bo){
        List<GoodsSkus> goodsSkusList = goodsService.selectSkuBy(bo);
        return R.ok(goodsSkusList);
    }

    /*首页一级分类下数据*/
    @GetMapping("/goods/list/{id}")
    public R<List<Goods>> selectByCate1Id(@NotNull(message="主键不能为空") @PathVariable Long id){
        List<Goods> goodssList = goodsService.selectByCate1Id(id);
        return R.ok(goodssList);
    }
}
